// vue 配置文件，可以配置 webpack的相关配置


//拿到 path ,需要先安装 npm install path@0 --save
const path = require('path')
//获取到 webpack
const webpack = require('webpack')

// 定义 resolve 函数供后续使用
function resolve(dir) {
    return path.join(__dirname, dir)
}


//webpack配置
module.exports = {
    //关闭语法检查
    lintOnSave: false,
    //代理配置
    devServer: {
        port: 80,
        host: "localhost",
        proxy: {
            '/api': {
                target: 'http://localhost:8608',  //代理地址
                //ws: true,  //proxy websockets
                changeOrigin: true,  // 跨域配置，如果接口跨域，需要进行这个参数配置
                pathRewrite: {
                    '^/api': '/'
                    //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
                    //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx
                }
            },
            '/foo': {
                target: '<other_url>'
            }
        }
    },

    //webpack配置
    configureWebpack: {
        resolve: {
            extensions: ['.js', '.vue', '.json'],
            //重命名
            alias: {
                '@': resolve('src'),
                /*'~': process.cwd(),
                public: resolve('public'),
                components: resolve('src/components'),
                util: resolve('src/utils'),
                store: resolve('src/store'),
                router: resolve('src/router')*/
            }
        }
    },
    chainWebpack(config) {

        //设置svg图标  set svg-sprite-loader
        config.module
            .rule('svg')
            .exclude.add(resolve('src/icons'))
            .end()
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
            .end()
    },
}
